package com.ysd.shiro.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ysd.common.utils.Json;
import com.ysd.shiro.entity.User;
import com.ysd.shiro.service.UserService;
import com.ysd.shiro.util.Response;
@RestController
@Slf4j
@RequestMapping("/ysd")
public class UserController {

	@Autowired
	private UserService userService;
	
    @Autowired
    private Response response;
    
    /**
     * 按照id进行查询
     */
    @RequestMapping("/findUserById/{userId}")
    // @RequiresPermissions("user:detail")
    public Json findUserById(@PathVariable("userId") int userId) {
    	User user =  userService.findUserById(userId);
    	return Json.success(user);
    }
    
    /**
     * 前台注册用户信息
     * @param user
     * @return
     */
    @RequestMapping("registerUser")
    public Json registerUser(User user) {
    	int flag = userService.addUser(user);    	
        return Json.success("success");
    }

    /**
     * 前台删除用户信息
     * @param user
     * @return
     */
    @DeleteMapping("/del/{userId}")
    //@RequiresRoles("role")
    public Json delUser(@PathVariable("userId") int userId) {
    	int flag = userService.delUserById(userId);
    	if(flag >=0) {
    		return Json.success("删除成功!");
    	} else {
    		return Json.fail("删除失败!");
    	}
    }
}
